Due 9/21, by the start of class.

R practice: Social Capital

This week, you’ll work with a newly released data set on social capital by the Opportunity Insights team, who used Facebook data to estimate three types of social capital – economic connectedness, cohesiveness, and civic engagement – across geography. The key measures are explained on their Social Capital Atlas and further detailed in the codebook (the readme.pdf file here) accompanying the data release.

We’ll use the county-level data. For our purposes, the key measures of interest include

You’ll start your own R markdown file to complete the following steps.

  1. Read the data in from the Opportunity Insights and create a state fips variable like so
library(tidyverse)
# you'll need to load additional libraries as well

# read data
soccap <- read_csv("https://data.humdata.org/dataset/85ee8e10-0c66-4635-b997-79b6fad44c71/resource/ec896b64-c922-4737-b759-e4bd7f73b8cc/download/social_capital_county.csv")

# make state fips code
soccap <- soccap %>% 
  mutate(county_fips = as.character(county),
         county_fips = str_pad(county_fips, width = 5, side = "left", pad = "0"),
         state_fips = str_sub(county_fips, 1,2))
  1. Choose any state you’d like (this is where the state fips codes are useful) and make a smaller dataset for just that state. Here’s a list of state fips codes.

  2. Pick one of the social capital variables listed above and visualize the distribution of that variable across the counties in you chosen state. What county exhibits the highest social capital based on this measure?

  3. Create a scatterplot of two of the measures of social capital and map the population to point size (e.g., a bubble chart). What does it suggest about these types of social capital in the state?

  4. Download the county shapefile for your chosen state using tigris; it should look something like

# for Virginia
va_counties <- counties(state = "51", cb = TRUE) 
  1. Join the dataset containing your chosen state’s measures to this county shapefile (you’ll want to list the sf object - the shapefile - first in the join command to retain the sf class in the resulting data object).

  2. Create a choropleth map of a key measure of social capital in your chosen state allowing the measure to vary continuously.

  3. Create a second choropleth map of the same key measure in your chose state, this time creating bins for the measure. Do the two versions lead you to similar interpretations or does one seem more useful in this context?

Submit your completed .Rmd file to me via slack!

Your Data

Draft of your final project to present next week! Load the knitted version of your draft project to slack before class so we can download and open it up in a browser from there!


xkcd inspiration